package com.tul.exercise.base.java8.stream.base;

import com.tul.exercise.base.java8.common.Constant;
import com.tul.exercise.base.java8.util.BeanAtributeHelper;
import com.tul.exercise.base.utils.MathUtils;
import org.omg.CORBA.TRANSACTION_MODE;

import java.util.ArrayList;
import java.util.List;

/**
 * 曲目类
 *
 * @author tuliang
 */
public class Track {
    /**
     * 曲目最长长度
     */
    private static final int MAX_LENGTH = 100;
    /**
     * 曲目名称
     */
    private String name;

    /**
     * 曲目长度
     */
    private Double length;

    public Track(String name, Double length) {
        this.name = name;
        this.length = length;
    }

    @Override
    public String toString() {
        return "Track{" +
                "name='" + name + '\'' +
                ", length=" + length +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Double getLength() {
        return length;
    }

    public void setLength(Double length) {
        this.length = length;
    }

    /**
     * 创建Track
     *
     * @return Track
     */
    public static Track createTrack() {
        String name = BeanAtributeHelper.getRandomItem(Constant.TRACKS_NAMES);
        Track track = new Track(name, Double.valueOf(MathUtils.getRandomInt(1, MAX_LENGTH)));
        return track;
    }

    /**
     * 创建曲目列表
     * @param num 个数
     * @return List
     */
    public static List<Track> createTracks(int num) {
        List<Track> list = new ArrayList<>(num);
        for (int i = 0; i < num; i++) {
            list.add(createTrack());
        }
        return list;
    }
}
